﻿//-----------------------------------------------------------------------
// <copyright file="CharacterClass.Data.cs" company="FastNET Services">
//     Copyright (c) 2008-2009. All Rights Reserved.
// </copyright>
// <license>
//     GPLv2
// </license>
// <warranty>
//     THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING
//     BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
//     NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
//     DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
//     OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
// </warranty>
//-----------------------------------------------------------------------
#region Usings

using System;
using System.Data;
using GateShift.Common.Repository;
using GateShift.Common.Repository.Interfaces.DataInterfaces;

#endregion

namespace GateShift.Services.GameData.Entities
{
    /// <summary>
    /// CharacterClass Entity Data Class
    /// </summary>
    internal partial class CharacterClass : ICharacterClassData
    {
        #region State Management

        /// <summary>
        /// Gets a value indicating whether or not this instance has been modified
        /// </summary>
        public bool IsDirty
        {
            get
            {
                if (IsNew)
                {
                    return true;
                }

                return EntityState == EntityState.Modified;
            }
        }

        /// <summary>
        /// Gets a value indicating whether or not this instance is new
        /// </summary>
        public bool IsNew
        {
            get
            {
                // Before it is attached if the key is null then we are new
                if (EntityState == EntityState.Detached)
                {
                    if (EntityKey == null)
                    {
                        return true;
                    }
                }

                return EntityState == EntityState.Added;
            }
        }

        /// <summary>
        /// Gets a value indicating whether or not this instance has been deleted
        /// </summary>
        public bool IsDeleted
        {
            get
            {
                return EntityState == EntityState.Deleted;
            }
        }

        #endregion

        #region Identity Management

        /// <summary>
        /// Gets or sets an Identity based reference for this item's Character
        /// </summary>
        Identity ICharacterClassData.CharacterID
        {
            get
            {
                return CharacterID;
            }

            set
            {
                if (!value.CanFitInGuid())
                {
                    throw new FormatException("CharacterID must be of Guid type");
                }

                CharacterID = value;
                CharacterReference.EntityKey = new EntityKey("EntityDataAdapter.Characters", "CharacterID", (Guid)value);
            }
        }

        /// <summary>
        /// Gets or sets an Identity based reference for this item's Class
        /// </summary>
        Identity ICharacterClassData.ClassID
        {
            get
            {
                return ClassID;
            }

            set
            {
                if (!value.CanFitInInt16())
                {
                    throw new FormatException("ClassID must be of short type");
                }

                ClassID = value;
                ClassReference.EntityKey = new EntityKey("EntityDataAdapter.Classes", "ClassID", (short)value);
            }
        }

        #endregion
    }
}